package org.jsets.fastboot.eventbus;

import java.lang.reflect.Method;
import lombok.extern.slf4j.Slf4j;

/**
 * 
 * 订阅者异常处理
 * @author wangjie
 *
 */
@Slf4j
public class SubscriberExceptionLoggingHandler implements SubscriberExceptionHandler{
	
	@Override
	public void handleException(Throwable exception, SubscriberExceptionContext context) {
		if (log.isErrorEnabled()) {
			log.error(message(context), exception);
		}
	}

	private static String message(SubscriberExceptionContext context) {
		Method method = context.getSubscriberMethod();
		return "Exception thrown by subscriber method "
	          + method.getName()
	          + '('
	          + method.getParameterTypes()[0].getName()
	          + ')'
	          + " on subscriber "
	          + context.getSubscriber()
	          + " when dispatching event: "
	          + context.getEvent();
	}

}